(function() {
	var w = (function() {
		var D = {};
		var E = [];
		D.inc = function(G, F) {
			return true
		};
		D.register = function(H, F) {
			var J = H.split(".");
			var I = D;
			var G = null;
			while (G = J.shift()) {
				if (J.length) {
					if (I[G] === undefined) {
						I[G] = {}
					}
					I = I[G]
				} else {
					if (I[G] === undefined) {
						try {
							I[G] = F(D)
						} catch(K) {}
					}
				}
			}
		};
		D.regShort = function(F, G) {
			if (D[F] !== undefined) {
				throw "[" + F + "] : short : has been register"
			}
			D[F] = G
		};
		D.IE = /msie/i.test(navigator.userAgent);
		D.E = function(F) {
			if (typeof F === "string") {
				return document.getElementById(F)
			} else {
				return F
			}
		};
		D.C = function(F) {
			var G;
			F = F.toUpperCase();
			if (F == "TEXT") {
				G = document.createTextNode("")
			} else {
				if (F == "BUFFER") {
					G = document.createDocumentFragment()
				} else {
					G = document.createElement(F)
				}
			}
			return G
		};
		D.log = function(F) {
			E.push("[" + ((new Date()).getTime() % 100000) + "]: " + F)
		};
		D.getErrorLogInformationList = function(F) {
			return E.splice(0, F || E.length)
		};
		return D
	})();
	$Import = w.inc;
	w.register("core.str.trim",
	function(D) {
		return function(H) {
			if (typeof H !== "string") {
				throw "trim need a string as parameter"
			}
			var E = H.length;
			var G = 0;
			var F = /(\u3000|\s|\t|\u00A0)/;
			while (G < E) {
				if (!F.test(H.charAt(G))) {
					break
				}
				G += 1
			}
			while (E > G) {
				if (!F.test(H.charAt(E - 1))) {
					break
				}
				E -= 1
			}
			return H.slice(G, E)
		}
	});
	w.register("core.evt.addEvent",
	function(D) {
		return function(E, H, G) {
			var F = D.E(E);
			if (F == null) {
				return false
			}
			H = H || "click";
			if ((typeof G).toLowerCase() != "function") {
				return
			}
			if (F.attachEvent) {
				F.attachEvent("on" + H, G)
			} else {
				if (F.addEventListener) {
					F.addEventListener(H, G, false)
				} else {
					F["on" + H] = G
				}
			}
			return true
		}
	});
	w.register("core.obj.parseParam",
	function(D) {
		return function(G, F, E) {
			var H,
			I = {};
			F = F || {};
			for (H in G) {
				I[H] = G[H];
				if (F[H] != null) {
					if (E) {
						if (G.hasOwnProperty[H]) {
							I[H] = F[H]
						}
					} else {
						I[H] = F[H]
					}
				}
			}
			return I
		}
	});
	w.register("core.arr.isArray",
	function(D) {
		return function(E) {
			return Object.prototype.toString.call(E) === "[object Array]"
		}
	});
	w.register("core.json.queryToJson",
	function(D) {
		return function(G, K) {
			var M = D.core.str.trim(G).split("&");
			var L = {};
			var F = function(O) {
				if (K) {
					return decodeURIComponent(O)
				} else {
					return O
				}
			};
			for (var I = 0, J = M.length; I < J; I++) {
				if (M[I]) {
					var H = M[I].split("=");
					var E = H[0];
					var N = H[1];
					if (H.length < 2) {
						N = E;
						E = "$nullName"
					}
					if (!L[E]) {
						L[E] = F(N)
					} else {
						if (D.core.arr.isArray(L[E]) != true) {
							L[E] = [L[E]]
						}
						L[E].push(F(N))
					}
				}
			}
			return L
		}
	});
	w.register("core.util.cookie",
	function(E) {
		var D = {
			set: function(I, L, K) {
				var F = [];
				var J,
				H;
				var G = E.core.obj.parseParam({
					expire: null,
					path: "/",
					domain: null,
					secure: null,
					encode: true
				},
				K);
				if (G.encode == true) {
					L = escape(L)
				}
				F.push(I + "=" + L);
				if (G.path != null) {
					F.push("path=" + G.path)
				}
				if (G.domain != null) {
					F.push("domain=" + G.domain)
				}
				if (G.secure != null) {
					F.push(G.secure)
				}
				if (G.expire != null) {
					J = new Date();
					H = J.getTime() + G.expire * 3600000;
					J.setTime(H);
					F.push("expires=" + J.toGMTString())
				}
				document.cookie = F.join(";")
			},
			get: function(H) {
				H = H.replace(/([\.\[\]\$])/g, "\\$1");
				var G = new RegExp(H + "=([^;]*)?;", "i");
				var I = document.cookie + ";";
				var F = I.match(G);
				if (F) {
					return F[1] || ""
				} else {
					return ""
				}
			},
			remove: function(F, G) {
				G = G || {};
				G.expire = -10;
				D.set(F, "", G)
			}
		};
		return D
	});
	w.register("core.util.browser",
	function(J) {
		var D = navigator.userAgent.toLowerCase();
		var M = window.external || "";
		var F,
		G,
		H,
		N,
		I;
		var E = function(O) {
			var P = 0;
			return parseFloat(O.replace(/\./g,
			function() {
				return (P++==1) ? "": "."
			}))
		};
		try {
			if ((/windows|win32/i).test(D)) {
				I = "windows"
			} else {
				if ((/macintosh/i).test(D)) {
					I = "macintosh"
				} else {
					if ((/rhino/i).test(D)) {
						I = "rhino"
					}
				}
			}
			if ((G = D.match(/applewebkit\/([^\s]*)/)) && G[1]) {
				F = "webkit";
				N = E(G[1])
			} else {
				if ((G = D.match(/presto\/([\d.]*)/)) && G[1]) {
					F = "presto";
					N = E(G[1])
				} else {
					if (G = D.match(/msie\s([^;]*)/)) {
						F = "trident";
						N = 1;
						if ((G = D.match(/trident\/([\d.]*)/)) && G[1]) {
							N = E(G[1])
						}
					} else {
						if (/gecko/.test(D)) {
							F = "gecko";
							N = 1;
							if ((G = D.match(/rv:([\d.]*)/)) && G[1]) {
								N = E(G[1])
							}
						}
					}
				}
			}
			if (/world/.test(D)) {
				H = "world"
			} else {
				if (/360se/.test(D)) {
					H = "360"
				} else {
					if ((/maxthon/.test(D)) || typeof M.max_version == "number") {
						H = "maxthon"
					} else {
						if (/tencenttraveler\s([\d.]*)/.test(D)) {
							H = "tt"
						} else {
							if (/se\s([\d.]*)/.test(D)) {
								H = "sogou"
							}
						}
					}
				}
			}
		} catch(L) {}
		var K = {
			OS: I,
			CORE: F,
			Version: N,
			EXTRA: (H ? H: false),
			IE: /msie/.test(D),
			OPERA: /opera/.test(D),
			MOZ: /gecko/.test(D) && !/(compatible|webkit)/.test(D),
			IE5: /msie 5 /.test(D),
			IE55: /msie 5.5/.test(D),
			IE6: /msie 6/.test(D),
			IE7: /msie 7/.test(D),
			IE8: /msie 8/.test(D),
			IE9: /msie 9/.test(D),
			SAFARI: !/chrome\/([\d.]*)/.test(D) && /\/([\d.]*) safari/.test(D),
			CHROME: /chrome\/([\d.]*)/.test(D),
			IPAD: /\(ipad/i.test(D),
			IPHONE: /\(iphone/i.test(D),
			ITOUCH: /\(itouch/i.test(D),
			MOBILE: /mobile/i.test(D)
		};
		return K
	});
	w.register("core.dom.isNode",
	function(D) {
		return function(E) {
			return (E != undefined) && Boolean(E.nodeName) && Boolean(E.nodeType)
		}
	});
	w.register("core.util.hideContainer",
	function(F) {
		var G;
		var D = function() {
			if (G) {
				return
			}
			G = F.C("div");
			G.style.cssText = "position:absolute;top:-9999px;left:-9999px;";
			document.getElementsByTagName("head")[0].appendChild(G)
		};
		var E = {
			appendChild: function(H) {
				if (F.core.dom.isNode(H)) {
					D();
					G.appendChild(H)
				}
			},
			removeChild: function(H) {
				if (F.core.dom.isNode(H)) {
					G && G.removeChild(H)
				}
			}
		};
		return E
	});
	window.WB2 = window.WB2 || {};
	WB2.Module = {
		loginButton: {
			versions: {
				"1.0": {
					js: "loginButton{ver}.js?version=20120327",
					css: "/t3/style/css/common/card.css?version=20120327"
				},
				latest: {
					js: "loginButton.js?version=20120327",
					css: "/t4/appstyle/widget/css/loginButton/loginButton.css"
				}
			}
		},
		followButton: {
			versions: {
				"1.0": {
					js: "followButton{ver}.js",
					css: "/t3/style/css/common/card.css?version=20120327"
				},
				latest: {
					js: "followButton.js?version=20120330",
					css: "/t4/appstyle/widget/css/followButton/followButtonSdk.css"
				}
			}
		},
		publish: {
			versions: {
				"1.0": {
					js: "publish{ver}.js?version=20120703",
					css: "/t3/style/css/thirdpart/rlsbox.css?version=20120327"
				},
				"1.1": {
					js: "publish{ver}.js?version=20120731",
					css: "/t35/appstyle/opent/css/widgets/js_weibo_send/js_weibo_send.css"
				},
				latest: {
					js: "publish.js?version=20120803",
					css: "/t4/appstyle/widget/css/weiboPublish/weiboPublish.css"
				}
			}
		},
		hoverCard: {
			versions: {
				"1.0": {
					js: "hoverCard{ver}.js?version=20120327",
					css: "/t3/style/css/common/card.css?version=20120327"
				},
				latest: {
					js: "hoverCard.js?version=20120820",
					css: "/t4/appstyle/widget/css/weiboCard/weiboCard.css"
				}
			}
		},
		recommend: {
			versions: {
				"1.0": {
					js: "recommend{ver}.js"
				},
				latest: {
					js: "recommend.js",
					css: "/t3/style/css/thirdpart/interested.css"
				}
			}
		},
		selector: {
			versions: {
				"1.0": {
					js: "selector{ver}.js?version=20120327",
					css: "/t3/style/css/thirdpart/csuser.css"
				},
				latest: {
					js: "selector.js?version=20120424",
					css: "/t4/appstyle/widget/css/selector/selector.css"
				}
			}
		},
		iframeWidget: {
			versions: {
				"1.0": {
					js: "iframeWidget{ver}.js?version=20120903"
				},
				latest: {
					js: "iframeWidget.js?version=20120903"
				}
			}
		}
	};
	w.register("core.func.getType",
	function(D) {
		return function(E) {
			var F;
			return ((F = typeof(E)) == "object" ? E == null && "null" || Object.prototype.toString.call(E).slice(8, -1) : F).toLowerCase()
		}
	});
	w.register("core.dom.ready",
	function(J) {
		var F = [];
		var O = false;
		var N = J.core.func.getType;
		var K = J.core.util.browser;
		var I = J.core.evt.addEvent;
		var L = function() {
			if (!O) {
				if (document.readyState === "complete") {
					return true
				}
			}
			return O
		};
		var G = function() {
			if (O == true) {
				return
			}
			O = true;
			for (var Q = 0, P = F.length; Q < P; Q++) {
				if (N(F[Q]) === "function") {
					try {
						F[Q].call()
					} catch(R) {}
				}
			}
			F = []
		};
		var D = function() {
			if (L()) {
				G();
				return
			}
			try {
				document.documentElement.doScroll("left")
			} catch(P) {
				setTimeout(arguments.callee, 25);
				return
			}
			G()
		};
		var E = function() {
			if (L()) {
				G();
				return
			}
			setTimeout(arguments.callee, 25)
		};
		var H = function() {
			I(document, "DOMContentLoaded", G)
		};
		var M = function() {
			I(window, "load", G)
		};
		if (!L()) {
			if (J.IE && window === window.top) {
				D()
			}
			H();
			E();
			M()
		}
		return function(P) {
			if (L()) {
				if (N(P) === "function") {
					P.call()
				}
			} else {
				F.push(P)
			}
		}
	});
	w.register("conf.api.wbml",
	function(D) {
		window.WB2 = window.WB2 || {};
		return function() {
			var F = D.core.util.browser;
			var I = [{
				tagName: "login-button",
				widgetName: "connectButton"
			},
			{
				tagName: "publish",
				widgetName: "publish"
			},
			{
				tagName: "follow-button",
				widgetName: "iframeWidget"
			},
			{
				tagName: "share-button",
				widgetName: "iframeWidget"
			},
			{
				tagName: "list",
				widgetName: "iframeWidget"
			},
			{
				tagName: "show",
				widgetName: "iframeWidget"
			},
			{
				tagName: "comments",
				widgetName: "iframeWidget"
			},
			{
				tagName: "livestream",
				widgetName: "iframeWidget"
			},
			{
				tagName: "bulkfollow",
				widgetName: "iframeWidget"
			},
			{
				tagName: "hotlist",
				widgetName: "iframeWidget"
			}];
			var H = function(J, O) {
				O = O || "wb";
				var K = navigator.userAgent.toLowerCase();
				var M = O + ":" + J;
				if (F.IE) {
					try {
						var N = document.namespaces;
						if (N && N[O]) {
							return document.getElementsByTagName(J).length == 0 ? document.getElementsByTagName(M) : document.getElementsByTagName(J)
						}
					} catch(L) {}
					return document.getElementsByTagName(M)
				} else {
					if (F.MOZ) {
						return document.getElementsByTagNameNS(document.body.namespaceURI, M)
					} else {
						return document.getElementsByTagName(M)
					}
				}
			};
			var G = function(N, M) {
				var L = N.attributes;
				var J = {};
				for (var K = L.length - 1; K >= 0; K--) {
					var O = L[K];
					if (O.specified) {
						J[L[K].name] = L[K].value
					}
				}
				J.dom = N;
				J.tagName = M;
				return J
			};
			var E = function() {
				var R = [];
				for (var M = 0, Q = I.length; M < Q; M++) {
					var J = I[M];
					var K = J.tagName;
					var N = J.widgetName;
					var P = H(K);
					for (var L = 0, O = P.length; L < O; L++) {
						R.push({
							tag: K,
							widget: N,
							params: G(P[L], K)
						})
					}
				}
				var Q = R.length;
				if (Q > 0) {
					WB2.anyWhere(function(T) {
						for (var V = 0, S = R.length; V < S; V++) {
							var U = R[V];
							T.widget[U.widget](U.params)
						}
					})
				}
			}; (function() {
				try {
					if (document.namespaces && !document.namespaces.item.wb) {
						document.namespaces.add("wb")
					}
				} catch(J) {}
			} ());
			WB2.initCustomTag = E;
			D.core.dom.ready(function() {
				E()
			})
		}
	});
	var d;
	var v = [];
	var m = 2;
	var a = "https://api.weibo.com/" + m + "/oauth2/query";
	var h = {};
	var j = w.core.obj.parseParam,
	q = w.core.evt.addEvent,
	s = w.core.str.trim,
	x = w.core.util.browser,
	f = w.core.util.cookie,
	z = w.core.json.queryToJson;
	var C = function(H) {
		var F = {
			url: "",
			charset: "UTF-8",
			timeout: 30 * 1000,
			args: {},
			onComplete: null,
			onTimeout: null,
			responseName: null,
			varkey: "callback"
		};
		var I = -1;
		F = j(F, H);
		var G = F.responseName || ("STK_" + Math.floor(Math.random() * 1000) + new Date().getTime().toString());
		F.args[F.varkey] = G;
		var D = F.onComplete;
		var E = F.onTimeout;
		window[G] = function(J) {
			if (I != 2 && D != null) {
				I = 1;
				D(J)
			}
		};
		F.onComplete = null;
		F.onTimeout = function() {
			if (I != 1 && E != null) {
				I = 2;
				E()
			}
		};
		return e(F)
	};
	var e = function(I) {
		var H,
		D;
		var E = {
			url: "",
			charset: "UTF-8",
			timeout: 30 * 1000,
			args: {},
			onComplete: null,
			onTimeout: null,
			uniqueID: null
		};
		E = j(E, I);
		if (E.url == "") {
			throw "url is null"
		}
		H = document.createElement("script");
		H.charset = "UTF-8";
		var J = /msie/i.test(navigator.userAgent);
		if (E.onComplete != null) {
			if (J) {
				H.onreadystatechange = function() {
					if (H.readyState.toLowerCase() == "complete" || H.readyState.toLowerCase() == "loaded") {
						clearTimeout(D);
						E.onComplete();
						H.onreadystatechange = null
					}
				}
			} else {
				H.onload = function() {
					clearTimeout(D);
					E.onComplete();
					H.onload = null
				}
			}
		}
		var G = function(L) {
			if (L) {
				var K = [];
				for (var M in L) {
					K.push(M + "=" + encodeURIComponent(s(L[M])))
				}
				if (K.length) {
					return K.join("&")
				} else {
					return ""
				}
			}
		};
		var F = G(E.args);
		if (E.url.indexOf("?") == -1) {
			if (F != "") {
				F = "?" + F
			}
		} else {
			if (F != "") {
				F = "&" + F
			}
		}
		H.src = E.url + F;
		document.getElementsByTagName("head")[0].appendChild(H);
		if (E.timeout > 0 && E.onTimeout != null) {
			D = setTimeout(function() {
				E.onTimeout()
			},
			E.timeout)
		}
		return H
	};
	var y = function() {
		this.started = 1;
		this.taskList = [];
		this.setStatue = function(D) {
			this.started = D
		};
		this.start = function() {
			this.setStatue(0);
			var F,
			H,
			E,
			G;
			var D = this.taskList.shift();
			var H = D[0],
			E = D[1],
			G = D[2];
			H.apply(G, E)
		};
		this.next = function() {
			this.setStatue(1);
			if (this.taskList.length > 0) {
				this.start()
			}
		};
		this.add = function(F, E) {
			var D = {
				args: [],
				pointer: window,
				top: false
			};
			D = j(D, E);
			if (D.top) {
				this.taskList.unshift([F, D.args, D.pointer])
			} else {
				this.taskList.push([F, D.args, D.pointer])
			}
			if (this.started) {
				this.start()
			}
		}
	};
	var p = new y();
	function u(E) {
		var D = WB2._config.version,
		G = WB2.anyWhere._instances,
		F = G[D];
		if (F) {
			if (F.contentWindow._ready) {
				F.contentWindow.request(E)
			} else {
				WB2.addToCallbacks(F.contentWindow, E)
			}
		} else {
			WB2.delayCall(E)
		}
	}
	function k(E) {
		var D = {
			requestType: "anywhere",
			callback: E
		};
		b(D)
	}
	function b(D) {
		var F = D || {};
		var E = function() {
			u(F);
			p.next()
		};
		var G = function(H) {
			if (h.bundle) {
				H && H()
			} else {
				e({
					url: WB2._config.host + "/open/api/js/api/bundle.js?version=" + WB2._config.cdn_version,
					onComplete: function() {
						h.bundle = 1;
						H && H()
					}
				})
			}
		};
		p.add(G, {
			args: [E]
		})
	}
	function n() {
		var G = document.getElementsByTagName("script");
		var I = G.length,
		H = 0,
		E,
		D,
		L,
		F,
		J;
		if (I > 0) {
			E = G[H++];
			while (E) {
				if (E.src.indexOf("api/js/wb.js") != -1) {
					D = E.src.split("?").pop();
					break
				}
				E = G[H++]
			}
		}
		D = D.toLowerCase();
		var K = z(D);
		L = K.appkey || "";
		F = K.secret || "";
		J = K.version || 1;
		return {
			appkey: L,
			secret: F,
			version: J
		}
	}
	function l(G, F) {
		var E,
		D;
		if (G != null) {
			if (F == true) {
				v.unshift(G)
			} else {
				v.push(G)
			}
		}
		if (WB2.checkLogin()) {
			for (E = 0, D = v.length; E < D; E++) {
				v[E].call()
			}
			v = []
		}
	}
	function o(F) {
		l(F, true);
		if (!WB2.checkLogin()) {
			var E = function(G) {
				c(G.status);
				if (G.success == 1) {
					i.save(G);
					l()
				} else {
					v.pop()
				}
			};
			var D = {
				appkey: WB2._config.appkey,
				requestType: "login",
				callback: E
			};
			b(D)
		}
	}
	function t(E) {
		if (!WB2.checkLogin()) {
			return
		}
		if (WB2._config.appkey != null) {
			i.del();
			c( - 1);
			try {
				C({
					url: "https://api.weibo.com/2/account/end_session.json?source=" + WB2._config.appkey,
					onComplete: function(F) {
						E && E(F.data)
					}
				})
			} catch(D) {
				throw "JavaScript SDK: logout error"
			}
		}
	}
	function c(D) {
		if (D == null) {
			return
		}
		d = D
	}
	function B() {
		return d == 1
	}
	var i = {
		load: function() {
			var E = f.get("weibojs_" + WB2._config.appkey);
			E = unescape(E);
			var D = z(E);
			return D
		},
		save: function(D) {
			var E = "access_token=" + (D.access_token || "") + "&refresh_token=" + (D.refresh_token || "") + "&expires_in=" + (D.expires_in || 0) + "&uid=" + (D.uid || "") + "&status=" + (D.status || d || -1);
			f.set("weibojs_" + WB2._config.appkey, E, {
				path: "/",
				domain: document.domain
			})
		},
		del: function() {
			f.remove("weibojs_" + WB2._config.appkey, {
				path: "/",
				domain: document.domain
			})
		}
	};
	function g(E) {
		var F = E || i.load();
		var G = F.access_token || "";
		var D = F.expires_in || "";
		if (G != "") {
			d = 1
		}
		C({
			url: a,
			onComplete: function(H) {
				H = H || {};
				if (H.status == 1 && H.access_token) {
					i.save(H)
				}
				d = H.status;
				l()
			},
			args: {
				source: WB2._config.appkey
			}
		})
	}
	var r = function(D) {
		if (D.access_token) {
			d = 1;
			var E = {
				status: d,
				access_token: D.access_token
			};
			i.save(E)
		}
	};
	window.WB2 = window.WB2 || {};
	WB2.widget = {};
	var A = n();
	WB2._config = {};
	WB2._config.version = A.version;
	WB2._config.appkey = A.appkey;
	WB2._config.secret = A.secret;
	WB2._config.host = "http://js.t.sinajs.cn";
	WB2._config.cssHost = "http://timg.sjs.sinajs.cn";
	WB2._config.cdn_version = "20120816";
	WB2.init = r;
	WB2.login = o;
	WB2.logout = t;
	WB2.checkLogin = B;
	WB2.anyWhere = k;
	WB2.anyWhere._instances = {};
	WB2.Cookie = i;
	WB2.regIframeRequest = b;
	WB2._config.appkey && g();
	w.conf.api.wbml()
})();